//判断横向是否有五颗
function crosswSuccess(checkerboard, row, col) {
    // 当前落子颜色
    const value = checkerboard[row][col]
    let num = 1;
    //判断左侧是否有五颗
    for (let i = col - 1; i >= 0; i--) {
        if (checkerboard[row][i] === value) {
            num += 1;
        } else {
            break
        }
    }
    //  判断右侧是否有五颗
    for(let i=col+1;i<15;i++){
        if(checkerboard[row][i] ===value){
            num +=1
        }else {
            break
        }
    }
    return num >=5
} 
// 判断纵向是否有五颗
function lengSuccess (checkerboard,row,col){
    const value = checkerboard[row][col]
    let num = 1;
    // 判断上方是否有五颗
    for (let i=row-1;i>=0;i--){
        if(checkerboard[i][col] === value) {
            num +=1
        }else {
            break
        }
    }
    // 判断下方是否有五颗
    for (let i=row+1;i<15;i++) {
        if(checkerboard[i][col] === value) {
            num+=1;
        }else {
            break
        }
    }
    return num >=5
} 
// 判断侧边是否有五颗
function leftSuccess (checkerboard,row,col ) {
    const value = checkerboard[row][col]
    let num = 1;
    // 左上
    for (let i =1; col-i>=0&&row-i>=0; i++){
        if(checkerboard[row-i][col-i]===value){
            num+=1;
        }else {
            break
        }
    }
    // 左下
    for (let i=1; col-i>=0&&row+i<15;i++) {
        if (checkerboard[row+i][col-i]===value){
            num+=1;
        }else {
            break
        }
    }
    // 右上
    for (let i=1; col+i<15&&row-i>=0; i++) {
        if(checkerboard[row-i][col+i]===value) {
            num+=1;
        }else {
            break
        }
    }
    
    // 右下
    for (let i=1; col+i<15&&row+i<15;i++){
        if(checkerboard[row+i][col+i] === value) {
            num+=1;
        }else {
            break
        }
    }
    return num >=5
}
export default function isSuccess(checkerboard,row,col ){
    return crosswSuccess(checkerboard,row,col) || lengSuccess(checkerboard,row,col) || leftSuccess(checkerboard,row,col)
}